<{include file="db:`$dirname`_header.html"}>

<div id="remittanceContent">
  <h3><{$smarty.const._MD_MILEAGE_LANG_REMITTANCE}></h3>
  <p><{$smarty.const._MD_MILEAGE_LANG_REMITTANCE_DESC}></p>

  <{if $actionForm->hasError()}>
    <ul class="error">
      <{foreach item=message from=$actionForm->getErrorMessages()}>
        <li><{$message|xoops_escape}></li>
      <{/foreach}>
    </ul>
  <{/if}>

  <div id="mileage_totalpoint">
    <p>
      <{$smarty.const._MD_MILEAGE_LANG_CURRENT_MILEAGE}>(<{$uid}>:<{$uid|xoops_user:uname}>)<br />
      <span style="font-size:200%;line-height:100%;"><{$totalPoint|intval}></span><br />
      <span><{$smarty.const._MD_MILEAGE_LANG_POINT}></span>
    </p>
  </div>

  <form action="<{$dirname|mileage_make_uri:Remittance}>" method="post" name="mileage_remittance">
    <table class="outer" summary="">
      <tbody>

        <tr>
          <th class="head"><{$smarty.const._MD_MILEAGE_LANG_UID}></th>
          <td class="<{cycle values="odd,even"}>">
            <{* xoops_input type=text name=toUid value="" id="remittance_uid" *}>
            <input type="text" name="toUid" id="remittance_uid" onBlur="mileage_get_uname()" />
            <a href="#" onClick="mileage_get_uname();return false;"><{$smarty.const._MD_MILEAGE_LANG_CONFIRM}></a>
            <div id="mileage_uname"></div>
          </td>
        </tr>

        <tr>
          <th class="head"><{$smarty.const._MD_MILEAGE_LANG_POINT}></th>
          <td class="<{cycle values="odd,even"}>">
            <{xoops_input type=text name=point value="" id="remittance_point"}>
          </td>
        </tr>

      </tbody>
      <tfoot>
        <tr>
          <td class="foot" colspan="2">
            <{xoops_token form=$actionForm}>
            <{xoops_input type=hidden name=mile_id value="0"}>
            <{xoops_input type=hidden name=uid value=""}>
            <{xoops_input type=hidden name=reg_unixtime value=""}>
            <{xoops_input type=hidden name=name value=""}>
            <{xoops_input type=hidden name=url value="remittance"}>
            <{xoops_input type=hidden name=suburl value="0"}>
            <{xoops_input type=hidden name=interval value="0"}>
            <{xoops_input type=hidden name=dirname value="$dirname"}>
            <input type="button" value="<{$smarty.const._SUBMIT}>" onClick="mileage_submit();" />
            <input type="submit" value="<{$smarty.const._CANCEL}>" name="_form_control_cancel" />
          </td>
        </tr>
      </tfoot>
    </table>
  </form>

  <br />

  <{if $remitedObjects}>
    <h3><{$smarty.const._MD_MILEAGE_LANG_REMITTANCE_LIST}></h3>
    <table class="outer">
      <thead>
        <tr>
          <th><{$smarty.const._MD_MILEAGE_LANG_MILE_ID}></th>
          <th><{$smarty.const._MD_MILEAGE_LANG_NAME}></th>
          <th><{$smarty.const._MD_MILEAGE_LANG_POINT}></th>
          <th><{$smarty.const._MD_MILEAGE_LANG_REG_UNIXTIME}></th>
          <th><{$smarty.const._MD_MILEAGE_LANG_REMITTANCE_STATUS}></th>
        </tr>
      </thead>
      <tbody>
        <{foreach item=obj from=$remitedObjects}>
          <tr class="<{cycle values='odd,even'}>">
            <td><{$obj->getShow('mile_id')}></td>
            <td><{$obj->getShow('name')}></td>
            <td><{$obj->getShow('point')}></td>
            <td><{$obj->getShow('reg_unixtime')|xoops_formattimestamp:l}></td>
            <td>
              <{if $obj->status}>
                <span class="received"><{$smarty.const._MD_MILEAGE_LANG_REMITTANCE_RECEIVED}></span>
              <{else}>
                <span class="not_received"><{$smarty.const._MD_MILEAGE_LANG_REMITTANCE_NOT_RECEIVED}></span>
              <{/if}>
            </td>
          </tr>
        <{/foreach}>
      </tbody>
    </table>
  <{/if}>

</div>

<{include file="db:`$dirname`_footer.html"}>

<script type="text/javascript" src="http://www.google.com/jsapi"></script>  
<script type="text/javascript">google.load("jquery", "1");</script>
<script type="text/javascript" charset="UTF-8">
<!--
jQuery.noConflict();
var post_flag = false;
function mileage_get_uname()
{
  var uid = jQuery('#remittance_uid').val();
  uid = parseInt(uid);
  var dummy_point = 1;
  if (post_flag == false) {
    if (check_uid_point(uid, dummy_point)) {
      post_flag = true;// TODO error?
      jQuery.post('<{$smarty.const.XOOPS_URL}>/modules/<{$dirname}>/get.php', {'page':'uname', 'uid':uid}, display_uname);
    }
  } else {
    alert('Waiting...');
  }
}
function display_uname(uname)
{
  if (uname == '') uname = 'NO USER';
  if (uname.length > <{$maxuname}>) {
    uname = uname.slice(0, <{$maxuname}>) + '...';
  }
  jQuery('#mileage_uname').text(uname);
  post_flag = false;
}
var mileage_error = '';
var send_uid = 0;
var send_point = 0;
function mileage_submit()
{
  var uid = jQuery('#remittance_uid').val();
  var point = jQuery('#remittance_point').val();
  if (post_flag == false) {
    if (check_uid_point(uid, point)) {
      send_uid = parseInt(uid);
      send_point = parseInt(point);
      post_flag = true;// TODO
      jQuery.post('<{$smarty.const.XOOPS_URL}>/modules/<{$dirname}>/get.php', {'page':'uname', 'uid':send_uid}, mileage_submit2);
    }
  } else {
    alert('Waiting...');
  }
}
function mileage_submit2(uname)
{
  post_flag = false;
  if (uname == '') {
    alert('<{$smarty.const._MD_MILEAGE_REMITTACE_NO_USER}>');
    return;
  } else if (uname.length > <{$maxuname}>) {
    uname = uname.slice(0, <{$maxuname}>) + '...';
  }
  if (check_uid_point(send_uid, send_point) && confirm(sprintf('<{$smarty.const._MD_MILEAGE_LANG_REMITTANCE_LAST_CONFIRM}>', {'uid':send_uid,'uname':uname, 'point':send_point}))) {
    document.mileage_remittance.submit();
  } else {
    return;
  }
}
function check_uid_point(uid, point)
{
  var result = false;
  if (uid == '' || uid <= 0) {
    alert('<{$smarty.const._MD_MILEAGE_REMITTACE_NO_UID}>');
  } else if (uid == <{$uid}>) {
    alert('<{$smarty.const._MD_MILEAGE_REMITTACE_NO_OWN}>');
  } else if (point <= 0 || point > <{$totalPoint|intval}>) {
    alert(sprintf('<{$smarty.const._MD_MILEAGE_LANG_REMITTANCE_POINT}>', {'point':<{$totalPoint|intval}>}));
  } else {
    result = true;
  }
  return result;
}
function sprintf(template, obj)
{
  var rslt = template;
  for (var Name in obj) {
    value = obj[Name];
    reg = new RegExp("#" + Name + "#", "g");
    rslt = rslt.replace(reg, value);
  }
  return rslt;
}
// -->
</script>
